home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Programming / yaec / docs / positron.txt < prev    next >
Encoding:
Text File  |  2001-08-12  |  14.3 KB  |  641 lines

  1.  
  2.  
  3. Positron (e+) is the name of this extended E language that YAEC compiles.
  4. _________________________________________________________________
  5.  
  6.  
  7. Positron adds some new simple types :
  8.  
  9. ANY, LONG, FLOAT
  10.  
  11. Okey, LONG is not exactly new.. but now it really acts as a LONG, that is,
  12. it can not be a ptr.
  13.  
  14. FLOAT  --  32bit single-precision IEEE float.
  15.  
  16. Maybe the most important type : ANY.
  17. Without it, not many old e-sources would compile.
  18. But its not only for backwards compability either.
  19.  
  20. How to define a varible as ANY :
  21.  
  22. DEF x, y:ANY  -> x and y are both of type ANY.
  23.  
  24. ANY  --  32bit untyped.
  25. ANY can be indexed as a PTR TO CHAR for backwards compability.
  26.  
  27. Ptr/array types :
  28.  
  29. There is also PTR TO ANY, ARRAY OF ANY as well as PTR TO FLOAT, ARRAY OF FLOAT.
  30.  
  31. PTR TO STRING, PTR TO LIST.
  32. Theese last two behaves like beeing a STRING,LIST but is not allocated.
  33. You may use NEW for that : NEW strptr[size]
  34. and END : END strptr
  35. same for listptrs.
  36. String(), List() is also okey to use.
  37.  
  38. That was a quick ride threw the types.
  39.  
  40.  
  41.  
  42. Type conflicts
  43. **************
  44.  
  45. -> this will be compiled okey
  46. ng:=[140, (20+topborder), 200, 12, '_Volume:   ', topaz80,
  47.        MYGAD_SLIDER, NG_HIGHLABEL, vi, 0]:newgadget
  48.  
  49. -> but not this
  50. ng:=[140, (20+topborder), 200, 12, '_Volume:   ', 123.123 ->topaz80,
  51.        MYGAD_SLIDER, NG_HIGHLABEL, vi, 0]:newgadget
  52. -> we replaced "topaz80" (PTR TO textattr)
  53. -> with "123.123" (FLOAT)
  54. -> theese type are not compatible and You will get a "type conflict".
  55.  
  56.  
  57.  
  58. Typed copy (assignment)
  59. ***********************
  60.  
  61. array := array2  -> this actually copies conents of "array2" into "array" !!
  62.  
  63. array := any -> as "any" _may_ be an array, (the compiler can not now for sure that it is _not_)
  64.                    -> conents pointed to by "any" will be copied into "array".
  65.  
  66. How did the compiler now how much to copy ?
  67. It did not get it from "any", no size declared there.
  68. It got it from the declaration of "array" !
  69.  
  70. DEF array[100]:ARRAY OF CHAR
  71.  
  72. 100 bytes would be copied in this case.
  73.  
  74. DEF array2[200]:ARRAY OF CHAR
  75.  
  76. still 100 bytes would be copied. there can never be any mem-overwrite.
  77.  
  78. any := array2
  79. -> this would just make "any" point to "array2", its the only logical thing to do.
  80.  
  81. Okey, what if using different types ?
  82.  
  83. string := ptr_to_long  -> this gives type error message.
  84.  
  85. But this would be okey :  
  86.  
  87. string := ptr_to_char  -> this actually equals "StrCopy(string, ptr_to_char)"                             
  88.  
  89. the other way around would the again just copy a ptr :
  90.  
  91. ptr_to_char := string -> "ptr_to_char" now points to "string".
  92.  
  93.  
  94. THE LEFTMOST VARIABLE ALWAYS DENOTES HOW ASSIGNMENT SHOULD BE DONE.
  95.  
  96. THE RIGHTMOST EXPRESSION JUST HAVE TO BE OF A COMPATIBLE TYPE.
  97.  
  98. "ANY" IS TYPELESS AND CAN SUBSTITUTE FOR ANY OTHER TYPE.
  99.  
  100. typed copy also works with object.members :
  101. obj.array := array
  102.  
  103. An Example:
  104. ---------------------------------------------
  105. DEF array[100]:ARRAY OF INT
  106.  
  107. PROC main()
  108.    array := bla()
  109. ENDPROC
  110.  
  111. PROC bla()
  112.    DEF array[100]:ARRAY OF INT
  113.    <fill array with values>
  114. ENDPROC array
  115. ----------------------------------------------
  116.  
  117. Here we used arrays as they where like any other values.
  118.  
  119.  
  120. YAEC comes with typed internal functions.
  121. ************************************************
  122.  
  123. ex :
  124.  
  125. StrCopy(s:PTR TO STRING, s2:PTR TO CHAR, len=ALL:LONG) (PTR TO STRING)
  126.  
  127. This would make compiler complain :
  128. DEF x:PTR TO LONG,y:LONG,z
  129. StrCopy(x, y, z)
  130.  
  131. both "x" and "y" are of incompatible types.
  132.  
  133. This on the other hand :
  134.  
  135. DEF x,y,z
  136. StrCopy(x,y,z)
  137.  
  138. is okey, cos the compiler can not be sure its NOT.
  139.  
  140. Better way to do it :
  141. DEF x[100]:STRING, z=10:LONG
  142. StrCopy(x, 'hello there!', z)
  143.  
  144.  
  145. So its best to try use typed variables where possible, else dont type em.
  146.  
  147. To turn off the typechecking, use "TCL -1" on the commandline.
  148.  
  149.  
  150. Cloning with NEW
  151. *******************
  152.  
  153. NEW can be used to "clone" variables :
  154.  
  155. DEF array[100]:ARRAY OF LONG, copy, string[100]:STRING
  156.  
  157. <fill array with values>
  158.  
  159. copy := NEW array
  160.  
  161. <put text in string>
  162.  
  163. copy := NEW string
  164.  
  165. -> "copy" now is an _exact_ copy of "string". _including_ maxlen and all that stuff.
  166.  
  167. NEW may as usual raise "MEM" if failing to allocate.
  168.  
  169. This works for objects too.
  170.  
  171. Another way to clone a string or list :
  172.  
  173. clone := CloneStr(stringptr)
  174.  
  175. clone := CloneList(listptr)
  176.  
  177. This time, only current length is allocated. (maxlen is not preserved).
  178.  
  179.  
  180. New preprocessor keywords, features
  181. *****************************************
  182.  
  183. "OPT PREPROCESS" not needed.
  184.  
  185. Conditional compilation : 
  186. #else keyword
  187.  
  188. Macros:
  189. #macro keyword
  190.  
  191. #macro supports varargs, types,... kicks ass :)
  192.  
  193. Better have a look at for example exec.e and amigalib.e
  194. to see how this keyword works.
  195.  
  196. #define keyword
  197.  
  198. Should not be used for expression-substitution anymore, use #macro for that.
  199. Still around for conditional compilation, typedefs,etc.. misc stuff.
  200.  
  201. IMPORT #define <name>  -> now what is this ??? :)
  202.  
  203. Imports an #define, defined in main-source, into a module.
  204. Can only be used in modules. (beta thingy)
  205.  
  206. #undef keyword   -> undo a #define
  207.  
  208.  
  209. Classes without using NEW
  210. *****************************
  211.  
  212. Classes (OBJECTs with methods) may now be allocated by simply
  213. typing something like : 
  214.  
  215. DEF o:classobject
  216.  
  217. Locally or globally.
  218.  
  219. At procedure/program end, an automatic "END o" is performed on the classobject.
  220. (including calling .end() method)
  221.  
  222. example :
  223.  
  224. PROC bla(x)
  225.    DEF o:object
  226. ENDPROC o.method(x)
  227.  
  228.  
  229. CONST keyword extended
  230. *****************************
  231.  
  232. Float constants :
  233.  
  234. CONST FLOATVAL=0.1263
  235.  
  236. Constant labels knows their type, for example, this would not slip 
  237. threw type-system :
  238.  
  239. CONST AAA=10, 
  240.       BBB=10.12345, 
  241.       CCC=AAA+BBB -> type error!
  242.  
  243.  not his either :
  244.  
  245. x := Max(AAA, BBB) -> type error, "BBB" is not integer.
  246.  
  247.  
  248. To make them OK :
  249.  
  250. CONST AAA=10,
  251.             BBB=10.12345,
  252.             CCC=AAA!+BBB  -> CCC= 20.12345
  253.  
  254. x := Max(AAA, !BBB!) 
  255.  
  256. Finally, "<<" and ">>" is allowed in constant expressions.
  257. (shift left, shift right)
  258.  
  259.  
  260. DATA keyword
  261. ****************
  262.  
  263. Data constants : (or : constant data pointers)
  264.  
  265. DATA MYLIST=[1,2,'hello',-0.9], MYARRAY=[1,2,3,4]:INT, 
  266.      MYSTRING='hello there'
  267.  
  268.  
  269. Next Gen Unification  (to be implemented..)
  270. ********************
  271.  
  272. This is nothing like the next-to-useless unification-mode
  273. found in old EC...
  274.  
  275. This is POWER ! :)
  276.  
  277. First type -> List-unification :
  278.  
  279. Compatible with EC list-unification.
  280.  
  281. exp <=> [1,2,x,y,BLA,[1,2,3]]  -> this is legal in EC and YAEC
  282.  
  283. exp <=> [123,*, x, obj.memb, BLA] 
  284. -> *=matches anything.
  285. -> objectmembers can also be used as variables.
  286. -> note : unification takes advantage of typed copy...!!   
  287.  
  288. exp <=> [<2, <>NIL, x, y, <=BLA, *, 10]
  289. -> think about this one for a while.. :)
  290.  
  291. it gets even worse..
  292. :)
  293.  
  294. exp <=> [<2|>10, *, x]
  295. -> |=OR
  296.  
  297. Second type -> object-unification :
  298.  
  299. As objects data is referenced by names, it makes sense to
  300. have a little different syntax for object-unification so that
  301. the data can still be referenced by name.
  302.  
  303. object <=> .memb1=NIL, x:=.memb4, .memb2<100|.method1(10)>1000
  304. -> note that there are no brackets here.
  305. -> methods can be used too, as seen above!
  306. -> if the comparisons match, then "x" gets the value of object.memb4
  307. -> "object" must be a variable declared as :object or PTR TO object.
  308. -> got it ? :)
  309.  
  310. Third type -> string-unification :
  311.  
  312. This will be very handy for stringmanipulating programs, for
  313. example compilers :)
  314.  
  315. exp <=> '<TAG>' + s + '</TAG>'
  316. -> very simple, but so extremely effective.
  317. -> If '<TAG>' and '</TAG>' is found in "exp"
  318. -> then copy everything between into estring "s".
  319. -> this equals roughly this code :
  320. match:=FALSE
  321. t := exp
  322. pos := InStr(t, '<TAG>') 
  323. IF pos <> -1
  324.    t := t + pos + STRLEN
  325.    pos := InStr(t, '</TAG>')
  326.    IF pos <> -1 
  327.       StrCopy(s, t, pos)
  328.       match := TRUE
  329.    ENDIF
  330. ENDIF
  331. -> but more efficient...
  332.  
  333.  
  334. -> "+" can also be used by list-unification :
  335.  
  336. [1,2,3,4,5,6,7,8,9,10,11,12,13] <=> [1,2,3] + x + [10,11,12]
  337. -> this will, if both above static lists are found (in order), 
  338. -> copy all between them into list "x".
  339. -> in this case [4,5,6,7,8,9]
  340.  
  341. List,object and string-unifications can be combined,
  342. in almost any ways :)
  343.  
  344.  
  345. Lisp-cells
  346. **********
  347.  
  348. Say goodbye.... :) I have NEVER had any use of lisp-cells..
  349.  
  350.  
  351. Sharing globals
  352. ****************
  353.  
  354. All globals that is to be shared between different
  355. modules, MUST be declared in main-program and then
  356. IMPORTed into modules that uses them.
  357. For backwards compability, EXPORT DEF ... is still
  358. legal. (but does the same as IMPORT DEF ...).
  359.  
  360.  
  361. Asm support
  362. ************
  363.  
  364. YAEC supports asm in a different way compared to EC.
  365. First off, it is not integrated into the language.
  366. This makes little sense for portability.
  367.  
  368. To insert a single line of asm :
  369.  
  370. ASM ' move.l d0, (a0)+'
  371.  
  372. To insert multiple lines of asm :
  373.  
  374. ASM
  375.   dc.l 0
  376. .label
  377.   move.l d0, a0
  378.  ...
  379.  ...
  380.  ...
  381. ENDASM
  382.  
  383. Asm-code is not touched or checked in any way by YAEC.
  384. This is up to the assembler, currently PhxAss.
  385.  
  386. To pass values between asm and E, YAEC can use 
  387. registers D0-D7/A0-A7 as variables :
  388.  
  389. ex:
  390.  
  391. x := A0
  392. D0 := blah()
  393.  
  394. You should not use registers D2-D7/A2-A5/A7 without
  395. saving/restoring them.
  396.  
  397.  
  398. List`N`Quote-functions
  399. **************************
  400.  
  401.    Slight API-change here.
  402.    same function, and some more.
  403.  
  404.    bool       := ForAll(list, qexp, qexp2=NIL)
  405.    bool, pos  := Exists(list, qexp, qexp2=NIL)
  406.    listvar    := MapList(list, listvar, qexp)
  407.    listvarlen := SelectList(list, listvar, qexp)
  408.  
  409.    Now. what happened to the {var} ?
  410.    Here it is : \x (and \y).
  411.  
  412.    In the above functions \x gives the
  413.    listitem and \y gives the listposition.
  414.  
  415.    qexp2 in ForAll() and Exists() will,
  416.    if <> NIL be evaluated IF the result
  417.    is TRUE. Then the result of qexp2 will
  418.    be returned instead.
  419.  
  420.    ex1 :
  421.  
  422.    Exists(list, `\x=14, `PrintF('yes, at pos \d\n', \y))
  423.  
  424.    ex2 : (slightly edited example from e.guide)
  425.  
  426. PROC main()
  427.   DEF mem[4]:LIST,x
  428.   MapList([200,80,10,2500],mem,`AllocVec(\x,0))              -> alloc some
  429.   WriteF(IF ForAll(mem,`\x) THEN 'Yes!\n' ELSE 'No!\n')        -> suxxes ?
  430.   ForAll(mem,`IF \x THEN FreeVec(\x) ELSE NIL)     -> free only those <>NIL
  431. ENDPROC
  432.  
  433.    Theese functions can be nested!
  434.  
  435.  
  436. Unary operators
  437. ****************
  438.  
  439.    ++/--
  440.  
  441.    The ++/-- operators works a bit more intelligent in YAEC.
  442.    In some cases though, this may break things.
  443.    In ec3.3a theese operators always affects the base-variable.
  444.    In YAEC ++/-- always affects the latest dereferenced `variable`.
  445.  
  446.    YAEC ex:
  447.       var++ -> affects var (as before)
  448.       var[]++ -> affects var (as before)
  449.       obj.member-- -> affects member !
  450.       self.member[]++ -> affects member !
  451.       obj.optr.member[]-- -> affects member !
  452.  
  453.    Especially when referencing self.xxx variables this will
  454.    be very handy. Instead of typing "self.ptr := self.ptr + SIZEOF LONG",
  455.    just type "self.ptr++" (if self.ptr is a PTR TO LONG :)).
  456.  
  457.    In other words : member or variable, same function.
  458.  
  459.  
  460.    ^ : This operator is not supported at the moment.
  461.  
  462.        Better is to use indexing ([]) or the Long() function to peek
  463.        into memory.
  464.  
  465.        [this operator is marked as obsolete in the ec3.3a E.guide]
  466.  
  467.  
  468. Removed keywords
  469. *****************
  470.  
  471.    o INC, DEC
  472.  
  473.       use ++ -- instead.
  474.  
  475.    o VOID
  476.  
  477.       VOID ? Anyone used it ? :)
  478.    YAEC18+ : This keyword may now be used for types.
  479.  
  480.  
  481. Removed functions
  482. ******************
  483.  
  484.    o CleanUp()   (use exceptions instead)
  485.  
  486.    o Gadget()
  487.  
  488. Jumping around  --    JUMP, LAB
  489. *******************************
  490.  
  491.    Theese keywords works locally to procedures.
  492.  
  493.    JUMP works like in ec.
  494.  
  495.    LAB is used to define a label.
  496.  
  497.    Ex:
  498.  
  499.    IF a THEN JUMP mylabel
  500.    ...
  501.    ...
  502.    LAB mylabel
  503.    ...
  504.    ...
  505.  
  506.    The nice thing about local labels in yaec is that they are
  507.    local... :) i.e. The same labels can be defined in several different
  508.    procedures without conflicts.
  509.  
  510.  
  511. Class variables
  512. ****************
  513.  
  514. This is an idea, but Im not sure if Ill implement it.
  515. What are they good for ?
  516. It is variables that all object of one class (and subclasses)
  517. have in common, they share them. In a language like Java,
  518. I can imagine it is very useful, because there are no globals
  519. (I think), but everything is wrapped in classes/objects.
  520. In E we got the module concept...
  521. As I can understand, there is not much difference declaring
  522. some gloals private in a module and declaring them private
  523. to a class in a module... ??
  524. So this is still pending..
  525.  
  526.  
  527. Anycase keywords
  528. ****************
  529.  
  530. This may be a HOT issue.
  531. Im seriously considering allowing keywords to be in lowercase too.
  532. I suspect a lot of people gets scared away by the big screaming keywords.. :)
  533. I know I was in the beginning. And from some looks at lowercase
  534. E sources, it kinda looks pretty nice, very soft.
  535. We`ll see in the future.
  536.  
  537.  
  538. Typed procedures/methods
  539. ************************
  540.  
  541. The syntax for this is inspired from PowerD (Martin Kouchinka)
  542.  
  543. ex:
  544.  
  545. PROC bla(x,y) (LONG) ...
  546.  
  547. Tells that this procedure/method returns ONE value
  548. which is of the type LONG.
  549.  
  550. If a function does not return anything, "VOID" may be used :
  551.  
  552. PROC compute(a,b) (VOID) ...
  553.  
  554.  
  555. now this is an error (compiler will complain) :
  556.  
  557. x := compute(a,b)
  558.      
  559.  
  560. If omitting the optional type-info (like in AmigaE), the procedure/method
  561. is considered as returning (ANY,ANY,ANY).
  562.  
  563.  
  564. Method-dereferencing
  565. ********************
  566.  
  567. Methods may now be dereferenced just as members!
  568.  
  569. object.method().member[].value .. etc..
  570.  
  571. For this to work, the method must be typed,
  572. and ofcource as returning some kind of object !
  573.  
  574. Ptr-typeing also works :
  575.  
  576. x := object.bla()::window.rport
  577.  
  578. for now, this ptr-typeing is not smart enough
  579. to react if .bla() returns a CHAR or INT...
  580.  
  581.  
  582. Dynamic typed lists (to be implemented..)
  583. or Complex types assignment
  584. or Stream Assign or similar :)
  585. *******************
  586.  
  587.  
  588. [1,2,3,x,y]>>l
  589.  
  590. equals :
  591.  
  592. l[0] := 1
  593. l[1] := 2
  594. l[2] := 3
  595. l[3] := x
  596. l[4] := y
  597.  
  598. "l" may be any LIST/ARRAY/PTR/OBJECT
  599.  
  600. bla(100,200,[1,2,3,x,y]>>l) 
  601. -> list passed is not static!
  602. -> using lists like this in librarymode, keeps the lists reentrant.
  603.  
  604. NEW [1,2,3,x,y]>>l
  605. -> this first does a "NEW l",
  606. -> then assigns values to "l".
  607.  
  608.  
  609. x := [1,2,*,*,y]>>l
  610.  
  611. equals:
  612.  
  613. l[0] := 1
  614. l[2] := 2
  615. l[5] := y
  616. x := l
  617.  
  618. -- Following two only with "l"=PTR --
  619.  
  620. x := [1,2,*,a]>>l++
  621.  
  622. equals :
  623.  
  624. l[]++ := 1
  625. l[]++ := 2
  626. l++
  627. l[]++ := a
  628. x := l
  629.  
  630.  
  631. x := [1,2,*,a]>>l--
  632.  
  633. equals :
  634.  
  635. l[]-- := 1
  636. l[]-- := 2
  637. l--
  638. l[]-- := a
  639. x := l
  640.  
  641.